USE [Capstone]
GO

/****** Object:  StoredProcedure [dbo].[SaveCalendar]    Script Date: 07/22/2012 22:43:17 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[SaveCalendar] 
	-- Add the parameters for the stored procedure here
@calID int = NULL,
@UserID int,
@ReasonID int,
@StartDate DateTime,
@EndDate DateTime,
@StatusID int,
@ParentID int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

if (@calID = 0)
Begin
	Insert into Calendar
		(UserID, ReasonID, StartDate, EndDate, StatusID, ParentID)
	Values
		(@UserID, @ReasonID, @StartDate, @EndDate, @StatusID, @ParentID)
End
Else
Begin
	Update Calendar set	
		UserID=@UserID, ReasonID=@ReasonID, 
		StartDate=@StartDate, EndDate=@StartDate,
		StatusID=@StatusID, ParentID=@ParentID
	Where
		calID=@calID

End
    -- Insert statements for procedure here
Select Scope_Identity();
END

GO

